import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
const addAbout = {
  namespaced: true,
  actions: {
    incrementOdd(context, value) {
      if (context.state.sum % 2) {
        context.commit("INCREMENT", value);
      }
    },
    incrementWait(context, value) {
      setTimeout(() => {
        context.commit("INCREMENT", value);
      }, 500);
    },
  },
  mutations: {
    INCREMENT(state, value) {
      state.sum += value;
    },
    DECREMENT(state, value) {
      state.sum -= value;
    },
  },
  state: { sum: 0 },
  getters: {
    bigSum(state) {
      return state.sum * 10;
    },
  },
};
const personAbout = {
  namespaced: true,
  actions: {
    addPersonWang(context, value) {
      if (value.name.indexOf("王") === 0) {
        context.commit("ADDPERSON", value);
        console.log(context);
      }
    },
  },
  mutations: {
    ADDPERSON(state, value) {
      state.PeopleList.unshift(value);
    },
  },
  state: { PeopleList: [{ id: "001", name: "米花" }] },
  getters: {},
};
export default new Vuex.Store({
  modules: {
    personAbout,
    addAbout,
  },
});
